<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<h1>System Info:</h1>
<ul id="dataList"></ul>

<script>
    // es = new EventSource("http://localhost:8199/subscribe/sysenv")
    es = new EventSource("https://zhgy.sagoo.cn/base-api/subscribe/sysenv")

    // bind the event listeners
    es.addEventListener("host", displayHost);
    es.addEventListener("mem", displayMem);
    es.addEventListener("cpu", displayCpu);
    es.addEventListener("sysLoad", displaySysLoad);
    es.addEventListener("disk", displayDisk);


    function displayHost(event) {
        var breed = event.data;
        _appendListItem("主机信息："+breed);
    }

    function displayMem(event) {
        var breed = event.data;
        _appendListItem("内存："+breed);
    }

    function displayCpu(event) {
        var breed = event.data;
        _appendListItem("CPU："+breed);
    }

    function displaySysLoad(event) {
        var breed = event.data;
        _appendListItem("负载信息："+breed);
    }

    function displayDisk(event) {
        var breed = event.data;
        _appendListItem("磁盘信息"+breed);
    }


    function _appendListItem(msg) {
        var li = document.createElement("li");
        li.innerHTML = msg;
        document.getElementById("dataList").appendChild(li);
    }
</script>
</body>
</html>
